package com.example.agriapp.view.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.agriapp.base.BaseFragment;
import com.example.agriapp.R;
import com.example.agriapp.model.bean.User;
import com.example.agriapp.util.SharedPrefUtils;
import com.example.agriapp.view.activity.CartActivity;
import com.example.agriapp.view.activity.FavoriteActivity;
import com.example.agriapp.view.activity.HistoryActivity;
import com.example.agriapp.view.activity.OrderActivity;
import com.example.agriapp.view.activity.SettingActivity;

import java.io.Serializable;

public class ProfileFragment extends BaseFragment  {

    public static ProfileFragment newInstance() {
        return new ProfileFragment();
    }
    
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_profile;
    }

    @Override
    protected void initView(View view) {
        TextView name = view.findViewById(R.id.userName);
        TextView userPhone = view.findViewById(R.id.userPhone);
        TextView realNameStatus = view.findViewById(R.id.realNameStatus);
        User user = (User) getActivity().getIntent().getSerializableExtra("USER");
        name.setText(user.getUsername());
        userPhone.setText(user.getPhone());
        realNameStatus.setText(user.getRealName());
        // 初始化各种点击事件
        view.findViewById(R.id.settingsButton).setOnClickListener(v->{
            startActivity(new Intent(getContext(), SettingActivity.class));
            //Toast .makeText(getContext(), "设置", Toast.LENGTH_SHORT).show();
        });
        view.findViewById(R.id.layout_cart).setOnClickListener(v -> {
            startActivity(new Intent(getContext(), CartActivity.class));
        });
//
        view.findViewById(R.id.layout_favorite).setOnClickListener(v -> {
            startActivity(new Intent(getContext(), FavoriteActivity.class));
        });

        view.findViewById(R.id.layout_history).setOnClickListener(v -> {
            startActivity(new Intent(getContext(), HistoryActivity.class));
        });
//
        view.findViewById(R.id.layout_order).setOnClickListener(v -> {
            startActivity(new Intent(getContext(), OrderActivity.class));
        });

        view.findViewById(R.id.linDaiFuKuan).setOnClickListener(v->{
            Toast.makeText(getContext(), "待付款", Toast.LENGTH_SHORT);
        });
        view.findViewById(R.id.linDaiFaHuo).setOnClickListener(v->{
            Toast.makeText(getContext(), "待发货", Toast.LENGTH_SHORT);
        });
        view.findViewById(R.id.linDaiShouHuo).setOnClickListener(v->{
            Toast.makeText(getContext(), "待收货", Toast.LENGTH_SHORT);
        });
        view.findViewById(R.id.linDaiPingJia).setOnClickListener(v->{
           Toast.makeText(getContext(), "待评价", Toast.LENGTH_SHORT);
        });
        view.findViewById(R.id.linTuiKuan).setOnClickListener(v->{
            Toast.makeText(getContext(), "退款/售后", Toast.LENGTH_SHORT);
        });
//
//        view.findViewById(R.id.layout_setting).setOnClickListener(v -> {
//            startActivity(new Intent(getContext(), SettingActivity.class));
//        });
//
//        mPresenter = new ProfilePresenter(this, new ProfileRepositoryImpl(getContext()));
//        mPresenter.subscribe();
    }
    
    @Override
    protected void initData() {
        // 数据初始化在initView中完成
    }
    
//    @Override
//    public void showUserInfo(User user) {
//        // 更新UI显示用户信息
//        TextView tvName = getView().findViewById(R.id.tv_name);
//        ImageView ivAvatar = getView().findViewById(R.id.iv_avatar);
//
//        tvName.setText(user.getName());
//        Glide.with(this).load(user.getAvatar()).into(ivAvatar);
//    }
//
//    @Override
//    public void showError(String message) {
//        Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
//    }
//
//    @Override
//    public void setPresenter(ProfileContract.Presenter presenter) {
//        mPresenter = presenter;
//    }
//
    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}